home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 21.7 KB | 756 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Gestalt.Lib
- #
- # Contains: xxx put contents here xxx
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.12> 12/8/93 KTA FormLongNumber() - Removed quitting the MathTool - if multiple
- # targets are running the tool will not be available.
- # <1.0.9> 12/3/93 KTA MachineState now returns logical and physical memory in bytes,
- # added FormLongNumber() task.
- # <1.0.8> 12/2/93 KTA Removed globals isOff, IsOn, VirtualMemory, notAvail, etc.
- # <1.0.7> 12/2/93 KTA Added tasks GestaltSystemArchitecture() and IsPowerPC(). Added
- # SystemArchitecture as MachineState() target descriptor.
- # <1.0.6> 11/30/93 ML Added ReturnMachineName parameter to GestaltMachineType, now
- # returns Machine umber by default
- # <1.0.5> 8/9/93 KTA MachineState() - Updates for new Pheonix data format .
- # <1.0.4> 7/19/93 KTA InitOnTarget had a syntax error that wasn't caught.
- # <1.0.3> 7/15/93 KTA Changed the name of some tasks so they wouldn't conflict with
- # Gestalt.vulib, changed error checking in InitOnTarget(), removed
- # SystemVersion() and MachineName().
- # <1.0.2> 6/8/93 NAGA unmark tasks that are not published
- # <1.0.1> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "OnTarget.Lib", "MathTool.vulib";
-
-
-
- ##################################################################################
- # Check32Bit()
- #=======================================================================
- # Author: GS
- # Description: This routine will check the state of 32 bit addressing,
- # and returns the value.
- # Parameters: None
- # Returns: Values
- # On := 1
- # Off := 0
- # not Avail := -1
- # GestaltError
- # in the first item a value described above. The second item is a text
- # string description of the value.
- #=======================================================================
- # History:
- #
- ##################################################################################
- Task Check32Bit()
- begin
- theResult := LowWordOfAnswer(gestalt( 'addr' ));
-
- if (theResult & (1 << 0))
- retVal := {1, "32 bit addressing is ON"};
-
- else if (theResult & (1 << 2))
- retVal := {0, "32 bit addressing is available but turned OFF"};
-
- else if not ((theResult & (1 << 0)) or (theResult & (1 << 1)) or (theResult & (1 << 2)))
- retVal := {-1, "32 bit addressing is not available on this machine"};
-
- if (gestRes[1])
- retVal := {gestRes[1], "Gestalt Error (-5550 is gestalt unavailable error)"};
-
- return retVal;
- end;
-
-
-
- ##################################################################################
- # CheckVM()
- #=======================================================================
- # Author: GS
- # Description: Checks to see if VM is turned on.
- #
- # Parameters: None
- # Returns: On := 1
- # Off := 0
- # not Avail := -1
- # GestaltError
- # if VM is on gestalt('vm ') returns a 1
- # any other case (not available, not turned on is a 0)
- #=======================================================================
- # History:
- # KTA 12/02/93 Removed isOff, IsOn, VirtualMemory, notAvail, etc.
- ##################################################################################
- TASK CheckVM()
- begin
- vmValue := LowWordOfAnswer(gestalt( 'vm ' ));
-
- if (vmValue = 0)
- begin
- theMMU := LowWordOfAnswer(gestalt( 'mmu ' ));
- if(theMMU > 1)
- retVal := {0, "VM is available and OFF"};
- else
- retVal := {-1, "VM is NOT available on this machine"};
- end;
-
- else if (vmValue & (1 << 0))
- retVal := {1, "VM is ON"};
-
- errorCode := gestRes[1];
- if (errorCode)
- retVal := {errorCode, "Gestalt Error (-5550 is gestalt unavailable error)"};
-
- return retVal;
- end;
-
-
-
-
- ##################################################################################
- # CheckCache()
- #=======================================================================
- # Author: GS
- # Description: Checks to see if caching is available and turned on, and returns
- # a value.
- #
- # Parameters: None
- # Returns: On := 1
- # Off := 0
- # not Avail := -1
- # GestaltError
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK CheckCache()
- begin
- if (GestaltProcessorType() = '68040')
- begin
- if(OnTargetInit())
- begin
- toolRes := OnTarget( 'CacheTest' )[2];
-
- if(toolRes = 1)
- retVal := {1, "040 Caches are ON"};
-
- if(toolRes = 2)
- retVal := {-1, "This isn't an '040, caching unavailable"};
-
- if(toolRes = 0)
- retVal := {0, "040 Caches are OFF"};
-
- OnTarget('Quit');
- end;
- else
- retVal := {-2,"We Don't know, can't launch OnTarget to find out"};
-
- end;
- else
- retVal := {-1, "This isn't an '040, caching unavailable"};
-
- return retVal;
- end;
-
-
-
- ##################################################################################
- # FileShare()
- #=======================================================================
- # Author: GS
- # Description: Checks to see if fileshare was installed and whether its switched on.
- #
- # Parameters: None
- # Returns: On := 1
- # Off := 0
- # not Avail:= -1
- # GestaltError
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK FileShare()
- begin
- if(OnTargetInit())
- begin
- theResult := OnTarget( 'FileShare' )[2];
-
- if(theResult = 0)
- retVal := {0, "FileSharing is available but NOT ENABLED"};
-
- else if(theResult = 1)
- retVal := {1, "FileSharing is ON"};
-
- else if(theResult = 2)
- retVal := {-1, "FileSharing is not available on theis machine"};
-
- else
- retVal := {-1, "Error checking status of Filesharing"};
-
- OnTarget('Quit');
- end;
- else
- retVal := {-2,"We Don't know, can't launch OnTarget to find out"};
-
- return(retVal);
- end;
-
-
-
- ##################################################################################
- # LowWordOfAnswer()
- #=======================================================================
- # Author: GS
- # Description: Returns second item of a list.
- #
- # Parameters: None
- # Returns: second item of a list
- #=======================================================================
- # History:
- #
- ##################################################################################
- task LowWordOfAnswer(Answer)
- begin
-
- tempVal := Answer[2];
- retVal := tempVal[2];
-
- return retVal;
- end;
-
-
- ##################################################################################
- # GestaltLongError()
- #=======================================================================
- # Author: GS
- # Description: Will return a longer error response in the form of a string.
- #
- # Parameters: None
- # Returns: String with error text
- #=======================================================================
- # History:
- #
- ##################################################################################
- task GestaltLongError(gestaltAnswer := {0,{0,0}})
- begin
- kGestaltNoErr := 0;
- kGestaltUnknownErr := -5550;
- kGestaltUndefSelectorErr := -5551;
-
- gesErr := gestaltAnswer[1];
- if gesErr = kGestaltNoErr
- return "No error";
- else if gesErr = kGestaltUnknownErr
- return "Error: Could not obtain response";
- else if gesErr = kGestaltUndefSelectorErr
- return "Error: Undefined selector";
- else
- return "Error: Unknown error code: {gesErr}";
- end;
-
-
-
-
-
- ##################################################################################
- # GestaltFPUType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Returns FPU type.
- #
- # Parameters: None
- # Returns: NoFPU
- # 68881
- # 68882
- # 68040
- # unknFPU
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK GestaltFPUType()
- begin
- gesAns := Gestalt('fpu ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- fpuAns := gesAns[2][2];
- if fpuAns = 0
- return "NoFPU";
- else if fpuAns = 1
- return "68881";
- else if fpuAns = 2
- return "68882";
- else if fpuAns = 3
- return "68040FPU";
- else
- return "unknFPU";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
-
- ##################################################################################
- # GestaltMachineType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Checks machine being tested and returns string with Machine Type.
- #
- # Parameters: None
- # Returns: String with Machine Name (See list below)
- #=======================================================================
- # History:
- # ML 11/30/93 Added ReturnMachineName parameter, now returns Machine
- # number by default
- ##################################################################################
- TASK GestaltMachineType(ReturnMachineName := 0)
- begin
- gesAns := Gestalt('mach');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- machAns := gesAns[2][2];
- if (ReturnMachineName)
- begin
- if machAns = 1
- return "Classic";
- else if machAns = 2
- return "MacXL";
- else if machAns = 3
- return "Mac512KE";
- else if machAns = 4
- return "MacPlus";
- else if machAns = 5
- return "MacSE";
- else if machAns = 6
- return "MacII";
- else if machAns = 7
- return "MacIIx";
- else if machAns = 8
- return "MacIIcx";
- else if machAns = 9
- return "MacSE030";
- else if machAns = 10
- return "Portable";
- else if machAns = 11
- return "MacIIci";
- else if machAns = 13
- return "MacIIfx";
- else if machAns = 17
- return "MacClassic";
- else if machAns = 18
- return "MacIIsi";
- else if machAns = 19
- return "MacLC";
- else if machAns = 20
- return "Quadra900";
- else if machAns = 21
- return "Powerbook170";
- else if machAns = 22
- return "Quadra700";
- else if machAns = 23
- return "ClassicII";
- else if machAns = 24
- return "PowerBook100";
- else if machAns = 25
- return "PowerBook140";
- else if machAns = 26
- return "Quadra 950";
- else
- return MachAns;
- end; # if ReturnMachineName
- else
- return MachAns;
- end; # if (not gesErr)
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltProcessorType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Returns the processor running on the test machine
- #
- # Parameters: None
- # Returns: 68000
- # 68010
- # 68020
- # 68030
- # 68040
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK GestaltProcessorType()
- begin
- gesAns := Gestalt('proc');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- procAns := gesAns[2][2];
- if procAns = 1
- return "68000";
- else if procAns = 2
- return "68010";
- else if procAns = 3
- return "68020";
- else if procAns = 4
- return "68030";
- else if procAns = 5
- return "68040";
- else
- return "unknProc";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
-
- ##################################################################################
- # GestaltMMUType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the memory management unit type found operating on the target.
- #
- #
- # Parameters: None
- # Returns: NoMMU
- # AMU
- # 68851
- # 68030MMU
- # 68040MMU
- # unknMMUType
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK GestaltMMUType()
- begin
- gesAns := Gestalt('mmu ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- mmuAns := gesAns[2][2];
- if mmuAns = 0
- return "NoMMU";
- else if mmuAns = 1
- return "AMU";
- else if mmuAns = 2
- return "68851";
- else if mmuAns = 3
- return "68030MMU";
- else if mmuAns = 4
- return "68040MMU";
- else
- return "unknMMUType";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltLogicalRAMSize()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the amount of logical RAM located in a machine.
- # (VM+RM)
- #
- #
- # Parameters: None
- # Returns: an integer in megabytes.
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK GestaltLogicalRAMSize()
- begin
- gesAns := Gestalt('lram');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- theHiWord := gesAns[2][1];
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltPhysicalRAMSize()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the amount of physical RAM located in a machine.
- #
- #
- # Parameters: None
- # Returns: an integer in megabytes.
- #=======================================================================
- # History:
- #
- ##################################################################################
- TASK GestaltPhysicalRAMSize()
- begin
- gesAns := Gestalt('ram ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- theHiWord := gesAns[2][1];
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # MachineState()
- #=======================================================================
- # Author: GS
- # Description: Returns a list of information concerning the state of the target
- # machine.
- #
- # Parameters: None
- # Returns: Gestalt Info
- #=======================================================================
- # History:
- # KTA 8/3/93 Rewrote - returns instead of prints info
- # KTA 12/3/93 Return logical and Physical memory in Bytes.
- ##################################################################################
- TASK MachineState(printMachineState := 0)
- begin
- targetDesc := match[target];
- match[system v:?SysVersion];
- if(IsPowerPC())
- sysa := 'PowerPC';
- else
- sysa := '68k';
-
- CPUType := { "CPUType", GestaltProcessorType()};
- MMUType := { "MMUType", GestaltMMUType()};
- FPUType := { "FPUType", GestaltFPUType()};
- MachineType := { "MachineType", GestaltMachineType()};
-
- TargetsName := { "TargetName", targetDesc.t};
- AddrMode := { "AddrMode", Check32Bit()[1]};
-
- ## logical Mem
- LogMem := FormLongNumber(Gestalt('lram')[2]);
- if not (logMem)
- begin
- LogicalMemMb := GestaltLogicalRAMSize();
- LogicalMemkBytes := LogicalMemMb*1024;
- logMem := "{LogicalMemkBytes}000";
- end;
- LogicalMem := { "LogicalMem",logMem };
-
- ## Physical Mem
- PhysMem := FormLongNumber(Gestalt('ram ')[2]);
- if not (PhysMem)
- begin
- PhysicalMemMb := GestaltPhysicalRAMSize();
- PhysicalMemkBytes := PhysicalMemMb*1024;
- PhysMem := "{PhysicalMemkBytes}000";
- end;
- PhysicalMem := { "PhysicalMem",PhysMem};
- VM := { "VM", CheckVM()[1]};
- FileSharing := { "FileShare", FileShare()[1]}; # Requires OnTarget
- Caches := { "Cache", CheckCache()[1]};
- MonitorBitDepth := { "BitDepth", targetDesc.s[1].p};
- SystemVersion := { "SysVersion", SysVersion};
- SystemArch := { "SystemArch", sysa};
-
- returnVal := {CPUType, MMUType, FPUType, MachineType, TargetsName, AddrMode, LogicalMem, PhysicalMem, VM, FileSharing, Caches, MonitorBitDepth, SystemVersion, SystemArch };
- if (printMachineState)
- begin
- for each item in returnVal
- println item[1], ": ",item[2];
- end;
-
- return(returnVal);
- end;
-
-
- #########################################################################
- # GestaltSystemArchitecture()
- #=======================================================================
- # Author: Kevin Avoy
- # Description: Makes a Gestalt call with selector of 'sysa' to determine if the
- # target system is 68K or PowerPC
- # Parameters: none
- # Returns: 0 - Selector not installed (older 68k)
- # 1 - Selector installed - target is 68k based not PowerPC
- # 2 - Selector installed - target is PowerPC based not 68k
- #=======================================================================
- # History:
- # KTA 12/01/93 Created
- ########################################################################
- TASK GestaltSystemArchitecture()
- begin
- gesAns := Gestalt('sysa');
- #println gesAns;
- if(GesAns[1] = -5551) # Selector not installed (older 68k machine)
- ReturnVal := 0;
- else if (GesAns[1] = 0)
- begin
- if( GesAns[2][2] = 1) # 68k system
- returnVal := 1;
- else if ( GesAns[2][2] = 2) # PowerPC native system
- returnVal := 2;
- else
- println "returnVal unknown - {gesAns}";
- end;
- else
- println " - a unexpected gestalt error occured - {gesAns}";
-
- return(ReturnVal);
- end;
-
- #########################################################################
- # IsPowerPC()
- #=======================================================================
- # Author: Kevin Avoy
- # Description: Makes a call to ProcessorType() to determine if the
- # target system is PowerPC or not
- # Parameters: none
- # Returns: 0 - not PowerPC
- # 1 - PowerPC
- #=======================================================================
- # History:
- # KTA 12/01/93 Created
- ########################################################################
- TASK IsPowerPC()
- begin
- returnVal := 0;
- sysa := GestaltSystemArchitecture();
- if(sysa = 2)
- returnVal := 1;
- return(returnVal);
- end;
-
- #########################################################################
- # OnTargetInit()
- #========================================================================
- #
- # Author: GS
- #
- # Description: Initializes OnTarget
- # Parameters: None
- # Returns: 1 - if OnTarget launched and initialized
- # 0 - if OnTarget could not launch
- #
- # Examples: OnTargetInit()
- #
- #========================================================================
- # History:
- # KTA 7/14/93 Changed error handling
- #########################################################################
- TASK OnTargetInit()
- begin
- returnVal := 0;
- IsError := OnTarget('Initialize',1);
- if(IsError[1]) # Some Error
- begin
- errorString := IsError[3];
- println "Ontarget initialization failed: ", errorString;
- end;
- else
- returnVal := 1;
-
- return (returnVal);
- end;
-
- #########################################################################
- # FormLongNumber(pHiLoList)
- #========================================================================
- # Author: KTA
- # Description: Forms a long (32 bit) numeric string from a high word 16-bit
- # number and a low word 16-bit number.
- # Parameters: pHiLoList - list of two elements.
- # 1st element is the hiWord number.
- # 2nd element is the loWord number.
- # Returns: returns a long (32 bit) numeric string
- # 0 - failure (some tool call probably failed.
- # Examples: FormLongNumber({ 122,-2304 });
- # Assumptions:
- #========================================================================
- # History:
- # KTA 12/3/93 Created
- # KTA 12/08/93 Removed quitting the MathTool - if multiple targets are running
- # the tool will not be available.
- #########################################################################
- Task FormLongNumber(pHiLoList := {})
- begin
- returnVal := 0;
- result := MathTool("Initialize", 0); # true - launch on the host
- if (result[1] <> 0 )
- begin
- println "MathTool could not be initialized"; # print error
- println "Error ", result[1], ". ", result[3] ;
- end;
- else
- begin
- HiWord := pHiLoList[1];
- loWord := pHiLoList[2];
-
- if (loWord < 0 ) # if loWord is less than zero add 1 to high word
- HiWord := HiWord + 1;
-
- TwoPower16 := MathTool("power", 2, 16);
- if (TwoPower16[1] <> 0 )
- begin
- println "MathTool could not perform Power service"; # print error
- println "Error ", TwoPower16[1], ". ", TwoPower16[3] ;
- end;
- else
- begin
- HiWordXTwoPower16 := MathTool("ftimes", TwoPower16[2], HiWord);
- if (HiWordXTwoPower16[1] <> 0 )
- begin
- println "MathTool could not perform ftimes service"; # print error
- println "Error ", HiWordXTwoPower16[1], ". ", HiWordXTwoPower16[3] ;
- end;
- else
- begin
- LogicalMemInBytes := MathTool("fplus", HiWordXTwoPower16[2], loWord);
- if (LogicalMemInBytes[1] <> 0 )
- begin
- println "MathTool could not perform fplus service"; # print error
- println "Error ", LogicalMemInBytes[1], ". ", LogicalMemInBytes[3] ;
- end;
- else
- returnVal := LogicalMemInBytes[2];
- end;
- end;
- #MathTool("Quit"); # Can not quit - if multiple targets are running the tool will not be available
- end;
- return(returnVal);
- end;
-